package com.jackson.engineeringtechnologyguide.aop;

/*
 * Author: JacksonCoder
 * FileName: ReturnLogAspect
 * Version: 1.0.0
 * Date: 2025/1/11
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import com.jackson.engineeringtechnologyguide.aop.ReturnLog;

import java.lang.reflect.Method;

@Slf4j
@Component
@Aspect
public class ReturnLogAspect {

    @Pointcut("@annotation(com.jackson.engineeringtechnologyguide.aop.ReturnLog)")
    private void pointcut() {

    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        // 获取目标类名称， 方法名称
        String clazzName = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();

        // 调用目标方法
        Object result = joinPoint.proceed();
        // 获取切点信息
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        ReturnLog returnLog = method.getAnnotation(ReturnLog.class);

        // 打印日志
        log.info("...");

        return result;
    }
}
